package com.balabala.gym_goods.controller.app;

import com.balabala.api.VipCardFeignClient;
import com.balabala.dto.VipCardDto;
import com.balabala.gym_goods.pojo.dto.AddNumDto;
import com.balabala.gym_goods.pojo.entity.Course;
import com.balabala.gym_goods.pojo.vo.CourseVo;
import com.balabala.gym_goods.service.CourseService;
import com.balabala.gym_system.api.AdvertisingFeignClient;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:zl
 * Date:2023/5/6 22:02
 */
@Slf4j
@RestController
@CrossOrigin
@Api(tags = "小程序团课详情接口")
@RequestMapping("/app/courseDetails")
public class CourseDetailsController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private AdvertisingFeignClient advertisingFeignClient;
    @Autowired
    private VipCardFeignClient vipCardFeignClient;

    @ApiOperation(value = "根据课程id查询详情")
    @GetMapping(value = "/findCourseById")
    public Result findCourseById(@RequestParam Long id) {
        Course byId = courseService.getById(id);
        return Result.ok(byId);
    }

    @ApiOperation(value = "根据课程id查询教练信息")
    @GetMapping(value = "/findCoachById")
    public Result findCoachById(@RequestParam Long id) {
        CourseVo courseById = courseService.findCourseById(id);
        return Result.ok(courseById);
    }

    @ApiOperation(value = "查询可用会员卡")
    @GetMapping(value = "/findVipCardById")
    public Result findVipCardById(@RequestParam Long id) {
        //调用查询可用会员卡feign接口
        Result<List<VipCardDto>> supportVipCardByCourseId = vipCardFeignClient.getSupportVipCardByCourseId(id);
        return Result.ok(supportVipCardByCourseId.getData());
    }

    @ApiOperation(value = "添加预约人数备注")
    @PostMapping(value = "/findVipCardById")
    public Result add(@RequestBody AddNumDto addNumDto) {
        //调用查询可用会员卡feign接口
        Result result = courseService.addNum(addNumDto);
        return Result.ok(result);
    }
}
